Error processing SSI file
LEADTOOLS Barcode (Leadtools.Barcode assembly)

Show in webframe

BarcodeData Constructor(BarcodeSymbology,Byte[])








Barcode symbology to use.
An array of Byte that specifies the data to use. This value can be null (Nothing in Visual Basic).
Initializes a new instance of the BarcodeData class with specified symbology and data.
Syntax
public BarcodeData( 
   BarcodeSymbology symbology,
   byte[] data
)
'Declaration
 
Public Function New( _
   ByVal symbology As BarcodeSymbology, _
   ByVal data() As Byte _
)
'Usage
 
Dim symbology As BarcodeSymbology
Dim data() As Byte
 
Dim instance As New BarcodeData(symbology, data)
public BarcodeData( 
   BarcodeSymbology symbology,
   byte[] data
)
- (instancetype)initWithSymbology:(LTBarcodeSymbology)symbology 
                             data:(nullable NSData *)data
            
public BarcodeData(
  BarcodeSymbology symbology,
  byte[] data
)
            
function BarcodeData( 
   symbology ,
   data 
)
public:
BarcodeData( 
   BarcodeSymbology symbology,
   array<byte>^ data
)

Parameters

symbology
Barcode symbology to use.
data
An array of Byte that specifies the data to use. This value can be null (Nothing in Visual Basic).
Remarks

This constructor initializes the BarcodeData member as follows:

Member Value
Symbology symbology
Bounds LogicalRectangle.Empty
RotationAngle 0
BarWidthReduction 0
Byte array inside GetData data (same reference, the data is not copied)
Value ASCII text string representation of data, if this parameter is null, then Value is null too.
Tag null (Nothing in Visual Basic)

To quickly construct a new BarcodeData object with a specific symbology and data as a string value, use BarcodeData(BarcodeSymbology symbology, string value) to construct a default BarcodeData, use BarcodeData().

To create an instance of BarcodeData suitable for writing for a specified symbology, use CreateDefaultBarcodeData.

Example

This example creates a BarcodeData using specified symbology and raw data. Then it writes it to an image.

Copy Code  
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Forms
Imports Leadtools.Barcode
Imports Leadtools.ImageProcessing

      
Public Sub BarcodeData_FromByteArrayExample()
   Dim outFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "MyBarcode.tif")
   ' This is UPC data to save a a string
   Dim originalString As String = "01234567890"

   ' We will get it as a byte array to use in the rest of this example
   Dim bytes() As Byte = Encoding.ASCII.GetBytes(originalString)

   ' Create a BarcodeData object from this data
   Dim data As New BarcodeData(BarcodeSymbology.UPCA, bytes)
   data.Bounds = New LogicalRectangle(0, 0, 400, 200, LogicalUnit.Pixel)

   ' Make sure it is the same
   Debug.Assert(data.Value = originalString)

   ' Write it to an image
   Dim engine As New BarcodeEngine()
   Using codecs As New RasterCodecs()
      Dim resolution As Integer = 300
      Dim pixels As LeadRect = data.Bounds.ToRectangle(resolution, resolution)
      Using image As RasterImage = RasterImage.Create(pixels.Width, pixels.Height, 1, resolution, RasterColor.FromKnownColor(RasterKnownColor.White))
         engine.Writer.WriteBarcode(image, data, Nothing)

         codecs.Save(image, outFileName, RasterImageFormat.Tif, 1)
      End Using
   End Using
End Sub

Public NotInheritable Class LEAD_VARS
Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Forms;
using Leadtools.Barcode;
using Leadtools.ImageProcessing;

      
public void BarcodeData_FromByteArrayExample()
{
   string outFileName = Path.Combine(LEAD_VARS.ImagesDir, @"MyBarcode.tif");
   // This is UPC data to save a a string
   string originalString = "01234567890";

   // We will get it as a byte array to use in the rest of this example
   byte[] bytes = Encoding.ASCII.GetBytes(originalString);

   // Create a BarcodeData object from this data
   BarcodeData data = new BarcodeData(BarcodeSymbology.UPCA, bytes);
   data.Bounds = new LogicalRectangle(0, 0, 400, 200, LogicalUnit.Pixel);

   // Make sure it is the same
   Debug.Assert(data.Value == originalString);

   // Write it to an image
   BarcodeEngine engine = new BarcodeEngine();
   using(RasterCodecs codecs = new RasterCodecs())
   {
      int resolution = 300;
      LeadRect pixels = data.Bounds.ToRectangle(resolution, resolution);
      using(RasterImage image = RasterImage.Create(pixels.Width, pixels.Height, 1, resolution, RasterColor.FromKnownColor(RasterKnownColor.White)))
      {
         engine.Writer.WriteBarcode(image, data, null);

         codecs.Save(image, outFileName, RasterImageFormat.Tif, 1);
      }
   }

}

static class LEAD_VARS
{
public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Barcode;
using Leadtools.ImageProcessing;

      
public async Task BarcodeData_FromByteArrayExample()
{
   string outFileName = @"MyBarcode.tif";
   // This is UPC data to save a a string
   string originalString = "01234567890";

   // We will get it as a byte array to use in the rest of this example
   byte[] bytes = Encoding.UTF8.GetBytes(originalString);

   // Create a BarcodeData object from this data
   BarcodeData data = new BarcodeData(BarcodeSymbology.UPCA, bytes);
   data.Bounds = LeadRectHelper.Create(0, 0, 400, 200);

   // Make sure it is the same
   Debug.Assert(data.Value == originalString);

   // Write it to an image
   BarcodeEngine engine = new BarcodeEngine();
   using(RasterCodecs codecs = new RasterCodecs())
   {
      int resolution = 300;
      LeadRect pixels = data.Bounds;
      using(RasterImage image = RasterImage.Create(pixels.Width, pixels.Height, 1, resolution, RasterColorHelper.FromKnownColor(RasterKnownColor.White)))
      {
         engine.Writer.WriteBarcode(image, data, null);

         StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(outFileName);
         await codecs.SaveAsync(image, LeadStreamFactory.Create(saveFile), RasterImageFormat.Tif, 1);
      }
   }

}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Forms;
using Leadtools.Barcode;
using Leadtools.ImageProcessing;
using Leadtools.Examples;

public void BarcodeData_FromByteArrayExample()
{
   // This is UPC data to save a a string
   string originalString = "01234567890";
   // We will get it as a byte array to use in the rest of this example
   byte[] bytes = Encoding.UTF8.GetBytes(originalString);

   // Create a BarcodeData object from this data
   BarcodeData data = new BarcodeData(BarcodeSymbology.UPCA, bytes);
   data.Bounds = new LogicalRectangle(0, 0, 400, 200, LogicalUnit.Pixel);

   // Make sure it is the same
   Debug.Assert(data.Value == originalString);

   // Write it to an image
   BarcodeEngine engine = new BarcodeEngine();
   RasterCodecs codecs = new RasterCodecs();

   int resolution = 300;
   LeadRect pixels = data.Bounds.ToRectangle(resolution, resolution);
   using(RasterImage image = RasterImage.Create(pixels.Width, pixels.Height, 1, resolution, RasterColor.FromKnownColor(RasterKnownColor.White)))
   {
      engine.Writer.WriteBarcode(image, data, null);

      using (SampleImageStream outputStream = new SampleImageStream("MyBarcode.tif"))
      {
         codecs.Save(image, outputStream, RasterImageFormat.Tif, 1);
      }
   }

}
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Forms
Imports Leadtools.Barcode
Imports Leadtools.ImageProcessing

Public Sub BarcodeData_FromByteArrayExample()
  ' This is UPC data to save a a string
  Dim originalString As String = "01234567890"
  ' We will get it as a byte array to use in the rest of this example
  Dim bytes As Byte() = Encoding.UTF8.GetBytes(originalString)

  ' Create a BarcodeData object from this data
  Dim data As BarcodeData = New BarcodeData(BarcodeSymbology.UPCA, bytes)
  data.Bounds = New LogicalRectangle(0, 0, 400, 200, LogicalUnit.Pixel)

  ' Make sure it is the same
  Debug.Assert(data.Value = originalString)

  ' Write it to an image
  Dim engine As BarcodeEngine = New BarcodeEngine()
  Dim codecs As RasterCodecs = New RasterCodecs()

  Dim resolution As Integer = 300
  Dim pixels As LeadRect = data.Bounds.ToRectangle(resolution, resolution)
  Using image As RasterImage = RasterImage.Create(pixels.Width, pixels.Height, 1, resolution, RasterColor.FromKnownColor(RasterKnownColor.White))
    engine.Writer.WriteBarcode(image, data, Nothing)

    Using outputStream As SampleImageStream = New SampleImageStream("MyBarcode.tif")
       codecs.Save(image, outputStream, RasterImageFormat.Tif, 1)
    End Using
  End Using

End Sub
Requirements

Target Platforms

See Also

Reference

BarcodeData Class
BarcodeData Members
Overload List

Error processing SSI file
Leadtools.Barcode requires a Barcode Module license and unlock key. For more information, refer to: LEADTOOLS Toolkit Features